package name.jiaosha.air.company.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import name.jiaosha.air.AppConstants;
import name.jiaosha.air.company.service.IGoodsService;
import name.jiaosha.air.system.domain.Goods;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.ali8ba.common.PageInfo;

@Controller
@RequestMapping("/admin/com")
public class GoodsController {

	@Autowired
	private IGoodsService goodsService;

	@RequestMapping("/goodsList")
	public ModelAndView goodsList() {

		PageInfo<Goods> pageInfo = null;

		if (!AppConstants.DEBUG) {
			List<Goods> list = new ArrayList<Goods>();
			for (int i = 0; i < 20; i++) {
				Goods goods = new Goods();
				goods.setId(i);
				goods.setName("铜管" + i);
				list.add(goods);
			}

		} else {

			pageInfo = goodsService.getGoodsListByComId(AppConstants.comId, 1,
					AppConstants.DEFAULT_SIZE);
		}

		ModelMap model = new ModelMap();
		model.addAttribute("root", pageInfo.getItemList());
		model.addAttribute("totalProperty", pageInfo.getTotalProperty());
		return new ModelAndView("jsonView", model);
	}

	@RequestMapping("/getGoods")
	public ModelAndView getGoods(@RequestParam int id) {

		Goods goods = null;

		
		ModelMap model = new ModelMap();
		if (!AppConstants.DEBUG) {

			goods = new Goods();
			goods.setId(1);
			goods.setName("铜管");

		} else {

			goods = goodsService.getGoodsById(id);
			if (goods != null) {

			}			
			model.addAttribute("unit", goods.getUnit());
			model.addAttribute("typeCode", "");
		}

		
		
		return new ModelAndView("jsonView", model);
	}

}
